<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>毕业论文管理系统</title>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<link rel="shortcut icon"
	href="${pageContext.request.contextPath }/favicon.ico"
	type="${pageContext.request.contextPath }/image/x-icon" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/css/font.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/css/xadmin.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-3.3.1.min.js"></script>
<script src="${pageContext.request.contextPath }/lib/layui/layui.js"
	charset="utf-8"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/xadmin.js"></script>

</head>
<body>
	<div class="x-body">
		<fieldset class="layui-elem-field">
			<legend>小组成员管理</legend>
			<c:choose><c:when test="${!empty teacher.studentList }">
			<table class="layui-table" style="width: 96%; margin: 2%">
				<thead>
					<tr>
						<th>学生学号</th>
						<th>学生姓名</th>
						<th>操作</th>
				</thead>
				<tbody>
				<c:forEach items="${teacher.studentList }" var="student">
					<tr>
						<td>${student.no }</td>
						<td>${student.name }</td>
						<td><button class="layui-btn" onclick="deletes('${student.no}')" lay-submit lay-filter="formDemo">删除成员</button></td>
					</tr>
				</c:forEach>
				</tbody>
			</table>
			</c:when>
			<c:otherwise>尚未分配学生</c:otherwise>
			</c:choose>
			<form>
				<div style="float: left; padding-left: 5%; padding-bottom: 10px;">
					选择一位新成员：
					<select id="stuno" name="stuno" style="width: 250px;">
					<c:choose><c:when test="${!empty noList }">
						<option value="">请选择一学生的学号</option>
						<c:forEach items="${noList }" var="no">
						<option value="${no }">${no }</option>
						</c:forEach>
					</c:when>
					<c:otherwise><option value="">没有学生可以选择</option></c:otherwise></c:choose>
					</select>
				</div>
				<div style="padding-left: 40%; padding-top: 7px;">
					<button id="btn1" onclick="add()" class="layui-btn layui-btn-normal">添加成员</button>
				</div>
			</form>
		</fieldset>
	</div>
</body>
<script>
function deletes(student_no){
	$.ajax({
		url : "${pageContext.request.contextPath }/teacher/deleteStudent.do",
		type : "post", 
		data : JSON.stringify({student_no:student_no}),
		contentType : "application/json;charset=UTF-8",
		dataType : "json",
		//成功响应的结果
		success : function(data){
			if(data != null){					
				layer.msg(data.msg,{time:2000});
			}
		}
  	}); 
}
function add(){
	var a=document.getElementById("stuno");
	var student_no=a.options[a.selectedIndex].value;
	$.ajax({
		url : "${pageContext.request.contextPath }/teacher/addStudent.do",
		type : "post", 
		data : JSON.stringify({student_no:student_no}),
		contentType : "application/json;charset=UTF-8",
		dataType : "json",
		//成功响应的结果
		success : function(data){
			if(data != null){					
				layer.msg(data.msg,{time:2000});
			}
		}
  	}); 
}

</script>
</html>